package com.briup.sxau.web.controller;

import com.briup.sxau.bean.Student;
import com.briup.sxau.service.IStudentService;
import com.briup.sxau.util.Result;
import com.briup.sxau.util.SxauException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("student")
@Api(tags = "学生管理模块")

public class StudentController {
    @Autowired
    IStudentService studentService;
    @ApiOperation("查询全部的学生信息带分页")
    @GetMapping("findAll")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "page",value = "当前页码必须大于0"),
            @ApiImplicitParam(name = "pageSize",value = "页面展示数据条数")
    })
    public Result findAll(int page,int pageSize){
        Page<Student> students = studentService.findAll(page, pageSize);
        return Result.success(students);
    }
    /*
     *通过id获取学生信息
     *@PathVariable 从url获取变量
     *
     **/
    @ApiOperation("使用id号查询学生的信息")
    @GetMapping("{id}")
    public Result findStudent(@PathVariable int id){

            Student student =studentService.findById(id);
            return Result.success(student);

    }
    @ApiOperation("使用id号来删除学生信息")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable int id){
        studentService.deleteById(id);
        return Result.success();
    }
    //新增学生信息
    @ApiOperation("新增学生信息，id没有设置主键自增，需要手动输入")
    @PostMapping("save")
    public Result save(@RequestBody Student student){

            studentService.save(student);
            return Result.success();


    }
}
